
# 引入requests模块
import requests
import json

# 将参数name和age定义到字典params中
params = {
    "name": "tony",
    "age": 20
}

# 定义访问url
url = "http://localhost:1903/test/testPost"

# 定义HTTP头信息
headers = {
    'Content-Type': 'application/json'
}

payload = {
    "name": "tony",
    "age": 20
}

payload_json_str = json.dumps(payload)

# post请求

res = requests.request("POST", url, headers=headers, data=payload_json_str)
# res = requests.post(url, payload_json_str, headers)

# 输出返回对象的文本结果
print(res.text)